﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine;
using Microsoft.Xna.Framework;

namespace Engine.Graphics
{
    public class SimpleAnimatedSprite : Sprite
    {
        Animation anim;

        bool isAnimating = true;

        public override Vector2 Origin
        {
            get
            {
                if (IsCentered)
                    return new Vector2(anim.FrameWidth / 2, anim.FrameHeight / 2);

                return Vector2.Zero;
            }
        }

        public override int Width
        {
            get { return anim.FrameWidth * (int)Scale.X; }
        }
        public override int Height
        {
            get { return anim.FrameHeight * (int)Scale.Y; }
        }

        public SimpleAnimatedSprite()
        {
        }

        public SimpleAnimatedSprite(string _texName, Animation _anim, bool _isCentered)
            : base(_texName, _isCentered)
        {
            anim = (Animation)_anim.Clone();
            DrawOffset = anim.DrawingOffset;
            SourceRectangle = anim.CurrentFrameRect;
        }

        public void Pause()
        {
            isAnimating = false;
        }

        public void Stop()
        {
            Pause();
            anim.Reset();
        }

        public void Play()
        {
            isAnimating = true;
        }

        public override void Update(GameTime _gameTime)
        {
            if (isAnimating)
            {
                anim.Update(_gameTime);
                SourceRectangle = anim.CurrentFrameRect;
            }
        }
    }
}
